﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ElevatorLib
{
    /// <summary>
    /// Exponential分布
    /// </summary>
    public class ExponentialDistr : IDistribution
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="rnd"></param>
        /// <param name="mean"></param>
        public ExponentialDistr(Random rnd, double mean)
        {
            if (mean <= 0.0)
            {
                mean = 0;
                throw new Exception("Mean must be greater than 0,0");
            }
            this.rnd = rnd;
            this.mean = mean;
        }

        #region Properties
        /// <summary>
        /// 随机数
        /// </summary>
        private Random rnd;
        /// <summary>
        /// 平均值，大于0
        /// </summary>
        private double mean;
        #endregion

        #region IDistribution 成员
        /// <summary>
        /// 生成数据
        /// </summary>
        /// <returns></returns>
        public double Sample()
        {
            double value = -mean * Math.Log(Math.E, rnd.NextDouble());
            return value;
        }

        #endregion
    }
}
